home *** CD-ROM | disk | FTP | other *** search
/ New Star Software Collection / NSS_Collection.iso / 3-170 dbase 10 for windows / 1.ima / SAMPLES.PAK / SHOWPROP.PRG < prev    next >
Text File  |  1993-07-26  |  5KB  |  161 lines

  1. *******************************************************************************
  2. *  PROGRAM:      Showprop.prg
  3. *
  4. *  WRITTEN BY:   Borland Late Night Crew
  5. *
  6. *  DATE:         4/8/93
  7. *
  8. *  UPDATED:
  9. *
  10. *  VERSION:      Alpha α
  11. *
  12. *  DESCRIPTION:  Showprop demonstrates Bladerunner's object model.  It shows
  13. *                how you can create your own objects, and also displays some
  14. *                of Bladerunner's stock objects.  Using these stock objects
  15. *                you can, for example, change the dimensions and captions of
  16. *                all Bladerunner windows.  This program shows how you could
  17. *                change your frame window and the Command window. It also
  18. *                demonstrates how you can view the properties of an object
  19. *                using the ENUM() function.
  20. *
  21. *                Showprop also shows how the object model lets you create
  22. *                sparse arrays. Because all objects support the index
  23. *                operator ([]), you can just assign a value to the [n]th
  24. *                property of an object. This will result in a sparse array
  25. *                of at least n elements.
  26. *
  27. *  PARAMETERS:   None
  28. *
  29. *  CALLS:        None
  30. *
  31. *  USAGE:        DO Showprop
  32. *
  33. *
  34. *
  35. *******************************************************************************
  36.  
  37. * _app is a stock object: the application
  38.  
  39.  
  40. * Save old captions
  41. private old_app_caption,old_command_caption
  42. old_app_caption = _app.caption
  43. old_command_caption = _app.commandwin.caption
  44.  
  45. ? "=== Enumeration of the application object: "
  46. enumprop( _app )
  47. wait
  48.  
  49. ? "=== Enumeration of one of the application's contained objects, commandwin:"
  50. ? enumprop( _app.commandwin )
  51. wait
  52.  
  53. * settable commandwin properties in build 11 are:
  54. *   caption
  55. *   left
  56. *   top
  57. *   height
  58. *   width
  59. *
  60. *   e.g. :
  61. ? "=== Property programming "
  62. _app.commandwin.left    =  10     && pixels are default unit for frame window
  63. _app.commandwin.width   = 500
  64. _app.commandwin.caption = "Gimme more properties!"
  65. _app.framewin.left      = 10
  66. _app.framewin.width     = _app.framewin.width - 100
  67. _app.caption            = "Properties to the max!"
  68.  
  69.  
  70.  
  71. * enum works for user defined objects, as well:
  72.  
  73. a = new object()    &&  temporary syntax; objbag() internally is a stock empty
  74.                     &&  object, a base for all bladerunner custom objects.
  75.                     &&  The actual syntax will be object().
  76.                     &&  'a = object()' is equivalent to 'a = new object()',
  77.                     &&  which will be final syntax for dynamically creating.
  78.                     &&  an empty object without first defining a class.
  79.                     &&
  80.                     &&  Syntax for instantiating a custom class (defined using
  81.                     &&  "class <class> [of <base class>] ) is not yet
  82.                     &&  implemented but will be "a = new myclass()"
  83.  
  84. ? "=== Enumeration of empty user defined object: "
  85. ? enumprop( a )     && object() is empty object, so this shows nothing
  86. wait
  87.  
  88. ? "=== Enumeration after dynamically adding properties"
  89. a.myprop  = 10
  90. a.myprop2 = 11
  91. a.myprop3 = 12
  92. ? enumprop( a )
  93. wait
  94.  
  95.  
  96. * Each object can be treated as array because all objects support the index
  97. * operator '[]'. The default behavior for an index is to create a sparse array
  98. * elements (where memory for cells is dynamically allocated only as necessary).
  99. ? "=== Objects as arrays: "
  100. a[ 5 ] = 11
  101. ? enumprop( a )
  102. wait
  103.  
  104. * Fixed arrays are also objects.  Arrays not only have index values, but also
  105. * have dynamic properties.
  106. ? "=== Arrays as objects: "
  107. declare x[ 5,5,5 ]
  108. x.myprop = 10
  109. ? enumprop( x )
  110. wait
  111.  
  112. * The memory management to implement this has other interesting implications
  113. * for arrays, e.g. typed arrays which require minimal memory, when types
  114. * are only int or logical. The type information is not stored, saving space.
  115.  
  116.  
  117.  
  118. * Reference model: You can store a reference to an object by simple assignment.
  119. * For example, to get a reference to the frame window, one would execute:
  120. ? "=== References: "
  121. z = _app.framewin
  122. * now z and _app.framewin reference the same window
  123. z.caption = "References to the max."
  124. wait
  125.  
  126. * Restore old captions
  127. _app.caption = old_app_caption
  128. _app.commandwin.caption = old_command_caption
  129.  
  130.  
  131.  
  132. *******************************************************************************
  133. function enumprop
  134.  
  135. * List all the properties of the parameter object by using Bladerunner's ENUM()
  136. * function.  ENUM() creates a linked list of the parameter object's
  137. * properties.  Each element of the list contains 3 properties:
  138. * Name -- the current property's name,
  139. * Value -- the current property's value,
  140. * Skip() -- a reference to the next property.
  141. * Eot -- end of table
  142. *******************************************************************************
  143.  
  144.     parameters o        && passed an object to enumerate
  145.  
  146.     e = new enum(o)
  147.     do while .not. e.eot
  148.         ? e.name + space( max(15 - len(e.name),0)) + "--->",e.value
  149.         x = e.skip(1)
  150.     enddo
  151.     ?
  152. return .f.
  153.  
  154.  
  155.  
  156.  
  157. *************************  End of Showprop.prg  *******************************
  158.  
  159.  
  160.  
  161.